Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor


Topic: Pseudocode for the modulo algorithm

January 28, 2016


The modulo operation is just the remainder after the division, rather than the quotient:

Modulo

Pseudo-code for calculating the modulo of two numbers:

input the number to be divided from the human user
input the divisor from the human user

set an intermediate variable to the number to be divided

while the intermediate is greater than or equal to the divisor do the following code in a loop
    subtract the divisor from the intermediate and store the result back into the intermediate variable
end of while loop

set remainder equal to the intermediate

output the remainder to the user


Same pseudo-code written closer to a real computer language:

Input number
Input divisor

intermediate <-- number

While intermediate >= divisor
    intermediate <-- intermediate - divisor
End While

remainder <-- intermediate

Output remainder





Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor